/* Base styles optimized for iframe and mobile-first design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
}

/* Main container adapts to iframe or full window */
#gameContainer {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    position: relative;
}

/* Detect if running in full window vs iframe */
@media (min-height: 500px) {
    #gameContainer {
        height: 90vh;
    }
}

/* Toolbar with essential controls */
#toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #2c3e50;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
    height: 50px;
}

.tool-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

#budgetDisplay, #cartDisplay {
    background: rgba(255,255,255,0.1);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-btn, .control-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    min-height: 36px; /* Touch-friendly size */
}

.tool-btn:hover, .control-btn:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.tool-btn:disabled, .control-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

/* Main game area layout */
#gameArea {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Room canvas - main play area */
#roomCanvas {
    flex: 2;
    background: #ecf0f1;
    position: relative;
    display: flex;
    flex-direction: column;
}

#room {
    flex: 1;
    background: #34495e;
    margin: 10px;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.3);
}

/* Grid overlay for easier furniture placement */
.room-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

#furnitureContainer, #ledContainer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

#furnitureContainer > * {
    pointer-events: all;
}

/* Room controls */
#roomControls {
    display: flex;
    gap: 8px;
    padding: 8px;
    justify-content: center;
}

/* Sidebar with panels */
#sidebar {
    flex: 1;
    background: white;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-left: 1px solid #ddd;
    max-width: 280px;
}

.panel {
    padding: 12px;
    border-bottom: 1px solid #eee;
}

.panel h3 {
    margin-bottom: 8px;
    color: #2c3e50;
    font-size: 14px;
    font-weight: 600;
}

/* Furniture catalog */
#furnitureGrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.furniture-item {
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    padding: 8px;
    cursor: grab;
    transition: all 0.2s;
    text-align: center;
}

.furniture-item:hover {
    border-color: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.furniture-item:active {
    cursor: grabbing;
}

.furniture-preview {
    width: 40px;
    height: 30px;
    margin: 0 auto 4px;
    border-radius: 3px;
}

.furniture-preview.bed {
    background: linear-gradient(45deg, #8e44ad, #9b59b6);
}

.furniture-preview.desk {
    background: linear-gradient(45deg, #e67e22, #f39c12);
}

.furniture-preview.nightstand {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
}

.furniture-preview.shelf {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.furniture-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.furniture-info .name {
    font-weight: 600;
    font-size: 12px;
    color: #2c3e50;
}

.furniture-info .dimensions {
    font-size: 10px;
    color: #7f8c8d;
}

/* Formula reference card */
.formula-card {
    background: #f8f9fa;
    border-radius: 6px;
    padding: 8px;
}

.formula-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 12px;
}

.shape-icon {
    font-size: 16px;
}

/* Achievement badges */
#badgeContainer {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 11px;
    transition: all 0.2s;
}

.badge.locked {
    background: #ecf0f1;
    color: #95a5a6;
}

.badge.unlocked {
    background: linear-gradient(45deg, #f39c12, #e67e22);
    color: white;
    animation: badgeUnlock 0.5s ease-out;
}

@keyframes badgeUnlock {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Placed furniture styles */
.placed-furniture {
    position: absolute;
    border: 2px solid #3498db;
    border-radius: 4px;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    transition: all 0.2s;
}

.placed-furniture:hover {
    border-color: #e74c3c;
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

.placed-furniture.measuring {
    border-color: #f39c12;
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.7);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* LED strip visualization */
.led-strip {
    position: absolute;
    background: linear-gradient(90deg, #ff0000, #00ff00, #0000ff, #ff0000);
    background-size: 10px 100%;
    border-radius: 2px;
    animation: ledFlow 2s linear infinite;
    box-shadow: 0 0 10px currentColor;
}

@keyframes ledFlow {
    0% { background-position: 0% 0%; }
    100% { background-position: 100% 0%; }
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 8px;
    max-width: 90%;
    max-height: 80%;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    0% { transform: translateY(-50px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.modal-header {
    background: #2c3e50;
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 16px;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
}

.modal-body {
    padding: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.modal-footer {
    padding: 12px 16px;
    background: #f8f9fa;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Shop modal specific styles */
.shop-item {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.led-preview {
    width: 60px;
    height: 40px;
    border-radius: 4px;
    border: 2px solid #ddd;
}

.shop-info h3 {
    margin-bottom: 4px;
    color: #2c3e50;
}

.price {
    color: #e74c3c;
    font-weight: bold;
    margin-bottom: 8px;
}

.quantity-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}

.quantity-controls input {
    width: 80px;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

.calculation-display {
    font-weight: bold;
    color: #27ae60;
}

/* Color picker */
.color-picker {
    margin-top: 16px;
}

.color-options {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.color-option {
    width: 30px;
    height: 30px;
    border: 2px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.color-option:hover, .color-option.selected {
    border-color: #2c3e50;
    transform: scale(1.1);
}

/* Button styles */
.btn-primary {
    background: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-primary:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.2s;
    max-width: 200px;
}

.tooltip.show {
    opacity: 1;
}

/* Success feedback */
.feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #27ae60;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    z-index: 1002;
    animation: feedbackShow 0.5s ease-out;
}

.feedback.show {
    display: flex;
}

@keyframes feedbackShow {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #gameArea {
        flex-direction: column;
    }
    
    #sidebar {
        max-width: none;
        max-height: 200px;
        border-left: none;
        border-top: 1px solid #ddd;
    }
    
    #furnitureGrid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .tool-btn, .control-btn {
        min-height: 44px; /* Larger touch targets on mobile */
        padding: 8px 12px;
    }
    
    .modal-content {
        max-width: 95%;
        margin: 10px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .furniture-item {
        border-width: 3px;
    }
    
    .placed-furniture {
        border-width: 3px;
    }
    
    .tool-btn, .control-btn {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}